<template>
  <div v-if="show" class="payment-modal">
    <div class="modal-content">
      <h2>{{ $t('buyNow') }}</h2>
      <p>商品名称：{{ product.name }}</p>
      <p>价格：${{ product.price }}</p>
      <div class="payment-options">
        <button @click="payWithAlipay">支付宝支付</button>
        <button @click="payWithWechat">微信支付</button>
      </div>
      <button @click="closeModal">取消</button>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  show: Boolean,
  product: Object
});

const emit = defineEmits(['close', 'success']);

function closeModal() {
  emit('close');
}

function payWithAlipay() {
  alert('正在跳转至支付宝...');
  setTimeout(() => {
    alert('支付成功！');
    emit('success');
  }, 1000);
}

function payWithWechat() {
  alert('正在跳转至微信支付...');
  setTimeout(() => {
    alert('支付成功！');
    emit('success');
  }, 1000);
}
</script>

<style scoped>
.payment-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal-content {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  width: 300px;
  text-align: center;
}

.payment-options button {
  display: block;
  width: 100%;
  margin: 10px 0;
  padding: 10px;
  font-size: 16px;
  cursor: pointer;
}
</style>